package routes

import (
	"aflow/controllers"
	"aflow/utils/middleware"
	"aflow/utils/sshTool"
	"github.com/gin-gonic/gin"
)

func SetupRouter() *gin.Engine {
	r := gin.Default()
	var sessionPool = sshTool.NewSSHPool()
	r.Use(middleware.SSHPoolMiddleware(sessionPool))

	api := r.Group("/api")
	{
		host := api.Group("/host")
		{
			host.GET("/", controllers.GetAllHost)
			host.GET("/:id", controllers.GetHost)
			host.POST("/", controllers.CreateHost)
			host.PUT("/:id", controllers.UpdateHost)
			host.DELETE("/:id", controllers.DeleteHost)
		}

		pipeline := api.Group("/pipeline")
		{
			pipeline.GET("/", controllers.GetAllPipeline)
			pipeline.GET("/:id", controllers.GetPipeline)
			pipeline.POST("/", controllers.CreatePipeline)
			pipeline.PUT("/:id", controllers.UpdatePipeline)
			pipeline.DELETE("/:id", controllers.DeletePipeline)
			pipeline.POST("exec/:id", controllers.ExecPipeline)
		}

	}

	return r
}
